<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
    <script src="__JS__/html2canvas.js"></script>
    <link href="__CSS__/toastr.css" rel="stylesheet"/>
    <link href="__CSS__/cover_layer.css" rel="stylesheet"/>
    <link href="__CSS__/general.css" rel="stylesheet"/>
    <script src="__JS__/toastr.js"></script>
    <script src="__JS__/cookie_operation.js"></script>



</head>
<body>


{if condition="isset($_COOKIE['user']) "}



<div id="work_top_window" style="position:absolute;width:100%;height:90px;background-color: rgb(246,246,246);">
    <!--项目名称part-->
    <div style="float: left;">
        <div onclick="location.href='{:url('index/getPublicCanvasLists')}'" style="cursor:pointer;font-size: 28px;margin-left: 20px; ">
            <img style="width:24px;height: 24px;" src="__IMG__/return.png">
            <text>小组:{$prjInfo.prj_name}</text></div>
    </div>

</div>



<div id="wholeCanvas" style="margin-top:60px;"><!--closing tag在business_canvas等3个单独的html里写-->

<div style="margin-bottom: 30px;margin-left: 220px;font-size: 20px;font-style: italic;">请选择你认为有价值的idea进行点赞~</div>



    {/if}

    <script>
        $('#header_cases').css('border-bottom','solid 2px #000000');
        $('#header_cases').css('font-weight','bold');


        //记录打开页面的时间
        window.onload = function () {
            $.ajax({
                type: "POST",
                url: "__PUBLIC__/index/index/addUserHistory",
                data: {
                    userId: "{$_COOKIE['user']}",
                    bh_type: "open_public",
                    toolId: '{$toolId}'
                },
                success: function (result) {
                    //console.log(result);
                }
            })
        };



        //关闭页面的时间
        window.onunload = function () {
            $.ajax({
                type: "POST",
                url: "__PUBLIC__/index/index/addUserHistory",
                data: {
                    userId: "{$_COOKIE['user']}",
                    bh_type: "close_public",
                    toolId: '{$toolId}'
                },
                success: function (result) {
                    //console.log(result);
                }
            })
        };



        //画布的  信息上边栏  随滚动条移动自动到达屏幕顶端
        var _box_y = $("#work_top_window").offset().top;
        $(window).scroll(function(){
            if($(window).scrollTop() > _box_y){
                $("#work_top_window").css("top",$(window).scrollTop()+"px");
                $("#work_top_window").css("z-index",99);
            }else{
                $("#work_top_window").css("top",_box_y);
            }
        });





        function favorColorSelection(recordId, likeCount,dislikeCount) {
            $.ajax({
                type: "POST",
                url: "__PUBLIC__/index/index/getLikeRelativeColor",
                data: {
                    likeCount:likeCount,
                    dislikeCount:dislikeCount,
                    threshold: 5
                },
                success: function (result) {
                    //console.log(result);
                    $('#like_color_' + recordId).css('background-color',result);
                }
            })
        }


        function likeSelection(ele, recordId) {

            if($(ele).attr('alt') == 'like_before' && $(ele).siblings('.dislike_selection').attr('alt') == 'dislike_before'){
                likeOrDislikeRecord(recordId,'{$_COOKIE['user']}', 'like');
                $(ele).attr('alt','like_after');
                $(ele).attr('src','__IMG__/like_after.png');

                var like_count = $(ele).siblings('.like_count').text();

                var new_like_count = '(' + (parseInt(like_count.substring(1,like_count.length - 1)) + 1) + ')';
                $(ele).siblings('.like_count').html(new_like_count);


                //即时更改颜色
                var dislike_count = $(ele).siblings('.dislike_count').text();
                favorColorSelection(recordId, parseInt(new_like_count.substring(1,new_like_count.length - 1)), parseInt(dislike_count.substring(1,dislike_count.length - 1)));
            }else if($(ele).attr('alt') == 'like_after'){
                cancelLikeOrDislikeRecord(recordId,'{$_COOKIE['user']}', 'like');
                $(ele).attr('alt','like_before');
                $(ele).attr('src','__IMG__/like_before.png');

                var like_count = $(ele).siblings('.like_count').text();

                var new_like_count = '(' + (parseInt(like_count.substring(1,like_count.length - 1)) - 1) + ')';
                $(ele).siblings('.like_count').html(new_like_count);


                //即时更改颜色
                var dislike_count = $(ele).siblings('.dislike_count').text();
                favorColorSelection(recordId, parseInt(new_like_count.substring(1,new_like_count.length - 1)), parseInt(dislike_count.substring(1,dislike_count.length - 1)));

            }
        }

        function dislikeSelection(ele, recordId) {
            if($(ele).attr('alt') == 'dislike_before' && $(ele).siblings('.like_selection').attr('alt') == 'like_before'){
                likeOrDislikeRecord(recordId,'{$_COOKIE['user']}', 'dislike');
                $(ele).attr('alt','dislike_after');
                $(ele).attr('src','__IMG__/dislike_after.png');

                var dislike_count = $(ele).siblings('.dislike_count').text();

                var new_dislike_count = '(' + (parseInt(dislike_count.substring(1,dislike_count.length - 1)) + 1) + ')';
                $(ele).siblings('.dislike_count').html(new_dislike_count);


                //即时更改颜色
                var like_count = $(ele).siblings('.like_count').text();
                favorColorSelection(recordId, parseInt(like_count.substring(1,like_count.length - 1)), parseInt(new_dislike_count.substring(1,new_dislike_count.length - 1)));

            }else if($(ele).attr('alt') == 'dislike_after'){
                cancelLikeOrDislikeRecord(recordId,'{$_COOKIE['user']}', 'dislike');
                $(ele).attr('alt','dislike_before');
                $(ele).attr('src','__IMG__/dislike_before.png');

                var dislike_count = $(ele).siblings('.dislike_count').text();

                var new_dislike_count = '(' + (parseInt(dislike_count.substring(1,dislike_count.length - 1)) - 1) + ')';
                $(ele).siblings('.dislike_count').html(new_dislike_count);


                //即时更改颜色
                var like_count = $(ele).siblings('.like_count').text();
                favorColorSelection(recordId, parseInt(like_count.substring(1,like_count.length - 1)), parseInt(new_dislike_count.substring(1,new_dislike_count.length - 1)));

            }
        }


        function likeOrDislikeRecord(recordId, userId, type) {
            $.ajax({
                type: "POST",
                url: "__PUBLIC__/index/index/likeOrDislikeRecord",
                data: {
                    recordId: recordId,
                    userId: userId,
                    like_or_dislike: type
                },
                success: function (result) {
                    //console.log(result);
                    //window.location.reload();

                }
            })
        }

        function cancelLikeOrDislikeRecord(recordId, userId, type) {
            $.ajax({
                type: "POST",
                url: "__PUBLIC__/index/index/cancelLikeOrDislikeRecord",
                data: {
                    recordId: recordId,
                    userId: userId,
                    like_or_dislike: type
                },
                success: function (result) {
                    //console.log(result);
                    //window.location.reload();

                }
            })
        }


        /**
         * 文本框根据输入内容自适应高度
         * @param                {HTMLElement}        输入框元素
         * @param                {Number}                设置光标与输入框保持的距离(默认0)
         * @param                {Number}                设置最大高度(可选)
         */
        var autoTextarea = function (elem, extra, maxHeight) {
            extra = extra || 0;
            var isFirefox = !!document.getBoxObjectFor || 'mozInnerScreenX' in window,
                isOpera = !!window.opera && !!window.opera.toString().indexOf('Opera'),
                addEvent = function (type, callback) {
                    elem.addEventListener ?
                        elem.addEventListener(type, callback, false) :
                        elem.attachEvent('on' + type, callback);
                },
                getStyle = elem.currentStyle ? function (name) {
                    var val = elem.currentStyle[name];

                    if (name === 'height' && val.search(/px/i) !== 1) {
                        var rect = elem.getBoundingClientRect();
                        return rect.bottom - rect.top -
                            parseFloat(getStyle('paddingTop')) -
                            parseFloat(getStyle('paddingBottom')) + 'px';
                    };

                    return val;
                } : function (name) {
                    return getComputedStyle(elem, null)[name];
                },
                minHeight = parseFloat(getStyle('height'));

            elem.style.resize = 'none';

            var change = function () {
                var scrollTop, height,
                    padding = 0,
                    style = elem.style;

                if (elem._length === elem.value.length) return;
                elem._length = elem.value.length;

                if (!isFirefox && !isOpera) {
                    padding = parseInt(getStyle('paddingTop')) + parseInt(getStyle('paddingBottom'));
                };
                scrollTop = document.body.scrollTop || document.documentElement.scrollTop;

                elem.style.height = minHeight + 'px';
                if (elem.scrollHeight > minHeight) {
                    if (maxHeight && elem.scrollHeight > maxHeight) {
                        height = maxHeight - padding;
                        style.overflowY = 'auto';
                    } else {
                        height = elem.scrollHeight - padding;
                        style.overflowY = 'hidden';
                    };
                    style.height = height + extra + 'px';
                    scrollTop += parseInt(style.height) - elem.currHeight;
                    document.body.scrollTop = scrollTop;
                    document.documentElement.scrollTop = scrollTop;
                    elem.currHeight = parseInt(style.height);
                };
            };

            addEvent('propertychange', change);
            addEvent('input', change);
            addEvent('focus', change);
            change();
        };


        function canvasScreenShoot() {
            html2canvas(document.querySelector("#wholeCanvas")).then(canvas => {

                $('body').html('<b>在以下画布区域右键“图片另存为”保存图片，重新编辑画布请刷新</b><br/><br/><br/><br/>');
            document.body.appendChild( canvas );

        });
        }




    </script>

